package net.world;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
import net.ServerMode;
import net.ServerMode.Mode;
import tools.DatabaseConnection;
import constants.ServerConstants;

/**
 *
 * @author Matze
 */
public class WorldServer {
    private static WorldServer instance = null;
    private int worldId;

    private WorldServer() {
        try {
            DatabaseConnection.getConnection();
        } catch (Exception e) {
        }
    }

    public synchronized static WorldServer getInstance() {
        if (instance == null) {
            instance = new WorldServer();
        }
        return instance;
    }

    public int getWorldId() {
        return worldId;
    }

    public static void main(String[] args) {
        ServerMode.setServerMode(Mode.WORLD);
        try {
            LocateRegistry.createRegistry(Registry.REGISTRY_PORT, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory()).rebind("WorldRegistry", WorldRegistryImpl.getInstance());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
